package com.etiantian.service;

import com.etiantian.db.OracleDBHelper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * Created by lujianing on 2014-7-24.
 */
@Service
public class GradeServiceImpl implements GradeService {

    @Override
    //@Cacheable(value="sixhour",key="'getOldOnlineCourse'+#grade_id")
    @Cacheable(value="sixhour")
    public void testTranscation() {
        System.out.println( OracleDBHelper.queryMapList("select * from grade_info", null));
        System.out.println( OracleDBHelper.queryMapList("select * from subject_info", null));
    }

    public void testUpdate(){
        //需要事务时单独开启事务
        OracleDBHelper.beginTransaction();
        OracleDBHelper.update("update grade_info set grade_name='高中三年级' where grade_id=1");
        //调用别的方法时，不要再开启事务，避免事务嵌套（建议service都调用dao，dao中的方法都是不开启事务的）
        update();
        OracleDBHelper.commitTransaction();
    }

    public void update(){
        OracleDBHelper.update("update grade_info set grade_name='11' where grade=1");
    }
}
